package com.heima.admin.controller.v1;

import com.heima.admin.services.ChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
    @Autowired
    private ChannelService channelService;

    @PostMapping("list")
    public ResponseResult list(@RequestBody ChannelDto dto) {

        return channelService.findByNameAndPage(dto);
    }

    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
    @ApiOperation(value = "添加频道",notes = "频道功能不为空，不能重复")
    @PostMapping("save")
        public ResponseResult insert(@RequestBody AdChannel channel) {
            return channelService.insert(channel);
        }
    @ApiOperation(value = "修改频道")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return channelService.update(channel);
    }
    @ApiOperation(value = "删除频道")
    @PostMapping("del/{id}")
    public ResponseResult update(@PathVariable Integer id) {
        return channelService.delete(id);
    }


}

